package com.demo.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.demo.core.exception.ParameterException;
import com.demo.dao.MyTeamViewDao;
import com.demo.domain.RegistrationInformation;
import com.demo.domain.TeamComposition;
import com.demo.domain.vo.MyTeamView;
import com.demo.service.MyTeamViewService;
import com.demo.service.RegistrationInformationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MyTeamViewServiceImpl extends ServiceImpl<MyTeamViewDao, MyTeamView> implements MyTeamViewService {
    @Autowired
    private MyTeamViewDao myTeamViewDao;

    @Autowired
    private TeamCompositionServiceImpl teamCompositionService;

    @Autowired
    private RegistrationInformationService registrationInformationService;

    @Override
    public List<MyTeamView> getAllTeamsInfoByUid(Long uid) throws ParameterException {
        if (uid==null||uid<0l){
            throw new ParameterException("uid为空或非法");
        }
//            当前存储了根据uid查出来的有该同学参加的队伍以及该队伍的信息
        List<MyTeamView> list = myTeamViewDao.selectMyTeamByUid(uid);
        TeamComposition teamComposition = new TeamComposition();
        RegistrationInformation registrationInformation = new RegistrationInformation();
        if (list != null || list.size() != 0) {
//            循环列表查找每个队伍的详情信息
            for (MyTeamView i : list) {
//                设置当前的队伍ID
                teamComposition.setTeamId(i.getTeamId());
                registrationInformation.setRiTeamId(i.getTeamId());
//                  将每个队伍的队伍成员进行查询封装
                List<TeamComposition> members = teamCompositionService.getTeamMember(teamComposition);
                i.setMembers(members);
//                    将每个队伍的入队申请进行查询封装
                List<RegistrationInformation> registrationList = registrationInformationService.getRegistration(registrationInformation);
                i.setRegistrationList(registrationList);
            }
        }
        return list;
    }
}
